export function submitIndustryFn(data, industryData) {
  const {lv1, lv2, lv3} = data;

  let submitDta = {
    csrcCodeLevel1: "",
    csrcCodeLevel2: "",
    gicsCodeLevel1: "",
    gicsCodeLevel2: "",
    hsCodeLevel1: "",
    hsCodeLevel2: "",
    swCodeLevel1: "",
    swCodeLevel2: "",
  };
  if (lv1.length === 0 && lv2.length === 0 && lv3.length === 0) {
    return submitDta
  }
  if (lv1[0] === "csrc") {
    submitDta.csrcCodeLevel1 = lv2.join(",");
    submitDta.csrcCodeLevel2 = lv3.join(",");
  } else if (lv1[0] === "gics") {
    submitDta.gicsCodeLevel1 = lv2.join(",");
    submitDta.gicsCodeLevel2 = lv3.join(",");
  } else if (lv1[0] === "hs") {
    submitDta.hsCodeLevel1 = lv2.join(",");
    submitDta.hsCodeLevel2 = lv3.join(",");
  } else if (lv1[0] === "sw") {
    submitDta.swCodeLevel1 = lv2.join(",");
    submitDta.swCodeLevel2 = lv3.join(",");
  }
  const codeObj = {
    'csrc': ['csrcCodeLevel1', 'csrcCodeLevel2'],
    'gics': ['gicsCodeLevel1', 'gicsCodeLevel2'],
    'hs': ['hsCodeLevel1', 'hsCodeLevel2'],
    'sw': ['swCodeLevel1', 'swCodeLevel2'],
  }
  //过滤三级code，如果三级code全选则不传三级code，只传二级code
  let swCodeLevel2Filter = submitDta[codeObj[lv1[0]][1]].split(",");
  submitDta[codeObj[lv1[0]][0]] &&
  submitDta[codeObj[lv1[0]][0]].split(",").forEach((item) => {
    let newData = industryData.value.filter((fitem) => fitem.code === lv1[0])[0]
      .values;
    newData = newData.filter((fitem2) => fitem2.code === item)[0].values;
    if (
      newData.every(
        (eveItem) => swCodeLevel2Filter.indexOf(eveItem.code) > -1
      )
    ) {
      newData.forEach((rItem) => {
        swCodeLevel2Filter.splice(swCodeLevel2Filter.indexOf(rItem.code), 1);
      });
    }
  });
  // Object.keys(submitDta).forEach((item) => {
  //   delete queryData[item]
  // })
  submitDta[codeObj[lv1[0]][1]] = swCodeLevel2Filter.join(",")
  return submitDta
}


export function submitIndicatorFn(data, industryData) {
  const {lv1, lv2, lv3} = data;
  let indicData:any = [];
  //获取所有指标的一级code
  lv1.forEach((item) => {
    industryData.forEach((titem) => {
      if (titem.code === item && titem.values.length == 0) {
        indicData.push(item);
      }
    });
  });
  //获取所有指标的二级code
  lv2.forEach((item) => {
    industryData.forEach((titem) => {
      titem.values &&
      titem.values.forEach((citem) => {
        if (citem.code === item && citem.values.length === 0) {
          indicData.push(item);
        }
      });
    });
  });
  //获取所有指标的三级code
  lv3.forEach((item) => {
    industryData.forEach((titem) => {
      titem.values &&
      titem.values.forEach((citem) => {
        citem.values &&
        citem.values.forEach((thitem) => {
          if (thitem.code === item && thitem.values.length === 0) {
            indicData.push(item);
          }
        });
      });
    });
  });
  return indicData.join(",")
}
